package com.jn.mvvm.viewmodel;

import androidx.lifecycle.ViewModel;

import com.jn.mvvm.entity.Book;

import java.util.ArrayList;
import java.util.List;

public class BookViewModel extends ViewModel {
    List<Book> mBookList = new ArrayList<>();

    public List<Book> getBookList() {
        return mBookList;
    }

    public void add(Book book) {
        Book newBook = new Book();
        newBook.setName(book.getName());
        newBook.setAuthor(book.getAuthor());
        mBookList.add(newBook);
    }

    public int getCount() {
        return mBookList.size();
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        //此处做资源回收等工作
    }
}
